﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AnnieSharp
{
    public class Matrix: AObject,ICloneable
    {
        /// <summary>
        /// a
        /// </summary>
        public float A { get; set; } = 1;
        /// <summary>
        /// b
        /// </summary>
        public float B { get; set; } = 0;
        /// <summary>
        /// c
        /// </summary>
        public float C { get; set; } = 0;
        /// <summary>
        /// d
        /// </summary>
        public float D { get; set; } = 1;
        /// <summary>
        /// tx
        /// </summary>
        public float Tx { get; set; } = 0;
        /// <summary>
        /// ty
        /// </summary>
        public float Ty { get; set; } = 0;

        public Matrix(float a = 1, float b = 0, float c = 0, float d = 1, float tx = 0, float ty = 0)
        {
            _instanceType = "annie.Matrix";
            A = a;
            B = b;
            C = c;
            D = d;
            Tx = tx;
            Ty = ty;
        }

        public object Clone() {
            return new Matrix(A, B, C, D, Tx, Ty);
        }



        /// <summary>
        /// 将一个点通过矩阵变换后的点
        /// </summary>
        /// <param name="x">x</param>
        /// <param name="y">y</param>
        /// <param name="bp">默认为空，如果不为null，则返回的是Point就是此对象，如果为null，则返回来的Point是新建的对象</param>
        /// <returns></returns>
        public Point TransformPoint(float x, float y, Point bp = null)
        {
            if (bp != null)
            {
                bp = new Point();
            }
            bp.X = x * A + y * C + Tx;
            bp.Y = x * B + y * D + Ty;
            return bp;
        }



    }
}
